package com.qf.smartplatform.controller;

import com.qf.smartplatform.dto.Result;
import com.qf.smartplatform.pojo.Role;
import com.qf.smartplatform.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * projectName:day12_27_Test
 * author:guoLei
 * time:2022/1/10 11:07
 * description:
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    private RoleService roleService;
    @Autowired
    public void setRoleService(RoleService roleService) {
        this.roleService = roleService;
    }
    @PostMapping("/addrole")
    public Result addRole(@RequestBody Role role){
        roleService.addRole(role);
        return Result.setOK();
    }
    @GetMapping("/roles")
    public Result getAllRole(){
        List<Role>roleList=roleService.selectAllRole();
        return Result.setOK(roleList);
    }
    @DeleteMapping("/deleterole")
    public Result deleteRole(List<Long>roleid){
        int i = roleService.deleteRoleByIds(roleid);
        return Result.setOK(i);
    }
    @PostMapping("/role/{id}")
    public Result getRoleById(@PathVariable Long id){
        Role role=roleService.selectById(id);
        return Result.setOK(role);
    }
    @GetMapping("rolename")
    public Result getRoleById(String roleName){
        System.out.println("=======");
        List<Role> roleList = roleService.selectRolesByNameLike(roleName);
        return Result.setOK(roleList);
    }

}
